/*
 *  $Id: VenomousSkin.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Water.Spells {
    public class VenomousSkin: SelfEnchantmentCard {
        public VenomousSkin(): base("001_w_s_venomous_skin") {
            Level = CompleteLevel.ReadyForTest;
            Version = 1;
            Element = ElementType.Water;
            Value = 100;
            AddManaCost(ElementType.Water, 3);
        }

        protected override EnchantmentAffect CreateEnchantment() {
            return new VenomousSkinAffect();
        }

        private class VenomousSkinAffect: EnchantmentAffect<VenomousSkin> {
            public override void SetAffect() {
                base.SetAffect();
                GlobalSummary.OnAfterDamage += DoDamage;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                GlobalSummary.OnAfterDamage -= DoDamage;
            }

            private void DoDamage(AbstractObject target, DamageInfo damage) {
                Creature attacker;
                if (!MeleeDamageInfo.TryGetAttacker(damage, out attacker)) return;
                Creature cr = target as Creature;
                if (cr != null && cr.Owner == Owner.Owner && cr.Card.Element == ElementType.Water)
                    attacker.AddAffect(new Affects.Venom(1));
            }
        }
    }
}
